﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using rock.DAL;
using System.Data.SqlClient;
using rock.UI.common;
using System.Threading;

namespace rock.UI.pictureinfo
{
    public partial class UserControlRoomAllInfo : UserControl
    {
        private int CONTRACT_SEQID = 0;
        public int _CONTRACT_SEQID { get { return CONTRACT_SEQID; } set { CONTRACT_SEQID = value; } }

        private int ROOM_SEQID = 0;
        public int _ROOM_SEQID { get { return ROOM_SEQID; } set { ROOM_SEQID = value; } }

        private int CUSTOM_SEQID = 0;
        public int _CUSTOM_SEQID { get { return CUSTOM_SEQID; } set { CUSTOM_SEQID = value; } }


        public UserControlRoomAllInfo()
        {
            InitializeComponent();
            this.Dock = DockStyle.Fill;
        }

        private void UserControlRoomAllInfo_Load(object sender, EventArgs e)
        {

           

            try
            {
               loadData();
            }
            catch (Exception)
            {
                
               // throw;
            }
           

            
        }

 

        public void loadData() {
            if (this._ROOM_SEQID > 0)
            {   //房间信息
                this.userControlImportRoomInfo1._ROOM_SEQID = this._ROOM_SEQID;
                this.userControlImportRoomInfo1.inits(this._ROOM_SEQID);
                this.userControlImportRoomInfo1._SHOW_BUTTON = false;
            }
            else
            {
               // MessageBox.Show("没有找到相关信息", "提示");
                return;
            }


            DataSet statusDs = DbHelperSQL.Query(String.Format("SELECT  SEQID ,RENT_CUSTOM_SEQID , HOUSE_ROOM_SEQID FROM RENT_CONTRACT WHERE STATUS = 1 AND HOUSE_ROOM_SEQID = {0}", this._ROOM_SEQID));
            if (statusDs != null && statusDs.Tables.Count > 0 && statusDs.Tables[0].Rows.Count > 0)
            {
                this._CONTRACT_SEQID = (int)statusDs.Tables[0].Rows[0]["SEQID"];
                this._CUSTOM_SEQID = (int)statusDs.Tables[0].Rows[0]["RENT_CUSTOM_SEQID"];



                if (this._CONTRACT_SEQID > 0)
                {
                    //合同信息
                    this.userControlImportRentContractInfo1._ROOM_SEQID = this._ROOM_SEQID;
                    this.userControlImportRentContractInfo1._CONTRACT_SEQID = this._CONTRACT_SEQID;
                    this.userControlImportRentContractInfo1._CUSTOM_SEQID = this._CUSTOM_SEQID;
                    this.userControlImportRentContractInfo1.inits(_CONTRACT_SEQID, _ROOM_SEQID, _CUSTOM_SEQID);
                    this.userControlImportRentContractInfo1._SHOW_BUTTON = false;

                    //客户信息
                    this.userControlImportCustomInfo1._CUSTOM_SEQID = this._CUSTOM_SEQID;
                    this.userControlImportCustomInfo1.inits(_CUSTOM_SEQID);
                    this.userControlImportCustomInfo1._SHOW_BUTTON = false;





                    //押金

                    SqlParameter[] Yparameters = {
                    new SqlParameter("@CONTRACT_SEQID", SqlDbType.Int, 4)
                                        };
                    Yparameters[0].Value = _CONTRACT_SEQID;
                    DataSet Yds = DbHelperSQL.RunProcedure("HOUSE_ROOM_DETAIL_YAJING", Yparameters, "ds");

                    //this.dataGridViewY.DataSource = Yds.Tables[0];

                    Decimal yajingAllMoney = 0;
                    DateTime yajingLastTime = new DateTime(2010, 1, 1);
                    for (int i = 0; i < Yds.Tables[0].Rows.Count; i++)
                    {
                        Decimal money = Decimal.Parse(Yds.Tables[0].Rows[i]["押金金额"].ToString());
                        yajingAllMoney += money;
                        DateTime date = DateTime.Parse(Yds.Tables[0].Rows[0]["录入时间"].ToString());
                        if (date > yajingLastTime)
                        {
                            yajingLastTime = date;
                        }
                    }
                    this.textBox1Yajing.Text = yajingAllMoney + "";
                    this.textBox2YaJingTime.Text = yajingLastTime.ToString(StringUtils.YYYYMMDD);





                    //租金
                    SqlParameter[] Zparameters = {
                    new SqlParameter("@CONTRACT_SEQID", SqlDbType.Int, 4)
                                        };
                    Zparameters[0].Value = _CONTRACT_SEQID;
                    DataSet Zds = DbHelperSQL.RunProcedure("HOUSE_ROOM_DETAIL_ZHUJING", Zparameters, "ds");
                    // this.dataGridViewZ.DataSource = Zds.Tables[0];

                    Decimal zhujingAllMoney = 0;
                    DateTime zhujingLastTime = new DateTime(2010, 1, 1);
                    for (int i = 0; i < Zds.Tables[0].Rows.Count; i++)
                    {
                        int status = int.Parse(Zds.Tables[0].Rows[i]["STATUS"].ToString());
                        if (status == Constant.FEE_ROOM_WEISHAO)
                        {
                            continue;
                        }
                        Decimal money = Decimal.Parse(Zds.Tables[0].Rows[i]["金额"].ToString());
                        zhujingAllMoney += money;
                        DateTime date = DateTime.Parse(Zds.Tables[0].Rows[0]["录入时间"].ToString());
                        if (date > zhujingLastTime)
                        {
                            zhujingLastTime = date;
                        }
                    }
                    this.textBox4ZhuJinag.Text = zhujingAllMoney + "";
                    this.textBox3ZhuJinagTime.Text = zhujingLastTime.ToString(StringUtils.YYYYMMDD);
                    //杂费
                    SqlParameter[] Odparameters = {
                    new SqlParameter("@CONTRACT_SEQID", SqlDbType.Int, 4)
                                        };
                    Odparameters[0].Value = _CONTRACT_SEQID;
                    DataSet Ods = DbHelperSQL.RunProcedure("HOUSE_ROOM_DETAIL_OTHERFEE", Odparameters, "ds");
                    // this.dataGridViewO.DataSource = Ods.Tables[0];
                    Decimal otherjingAllMoney = 0;
                    DateTime otherjingLastTime = new DateTime(2010, 1, 1);
                    for (int i = 0; i < Ods.Tables[0].Rows.Count; i++)
                    {
                        int status = int.Parse(Ods.Tables[0].Rows[i]["STATUS"].ToString());
                        if (status == Constant.FEE_ROOM_WEISHAO)
                        {
                            continue;
                        }
                        Decimal money = Decimal.Parse(Ods.Tables[0].Rows[i]["金额"].ToString());
                        otherjingAllMoney += money;
                        DateTime date = DateTime.Parse(Ods.Tables[0].Rows[0]["录入时间"].ToString());
                        if (date > otherjingLastTime)
                        {
                            otherjingLastTime = date;
                        }
                    }
                    this.textBox6Other.Text = otherjingAllMoney + "";
                    this.textBox5OtherTime.Text = otherjingLastTime.ToString(StringUtils.YYYYMMDD);
                }


            }
        
        }
    }
}
